package com.ate.aoligei.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.ate.aoligei.R;
import com.ate.aoligei.base.BaseActivity;
import com.ate.aoligei.contract.Contract;
import com.ate.aoligei.presenter.LoginPresenter;

public class LoginActivity extends BaseActivity implements Contract.LoginView {
    private EditText loginName;
    private EditText loginPwd;
    private Button login;
    LoginPresenter loginPresenter;
    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected void init() {
        super.init();
        loginPresenter = new LoginPresenter(this);
        loginName = (EditText) findViewById(R.id.login_name);
        loginPwd = (EditText) findViewById(R.id.login_pwd);
        login = (Button) findViewById(R.id.login);
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loginPresenter.login(loginName.getText().toString().trim(),loginPwd.getText().toString().trim());
                showProgress();
            }
        });
    }

    @Override
    public void onSuccess() {
        dismissProgress();
        Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void onError(String msg) {
        dismissProgress();
        Toast.makeText(this, "登录失败", Toast.LENGTH_SHORT).show();
        dismissProgress();
    }

}